//author:kakake
class tspayController {
    public data = {
        dbConn: TSLobsterAPI.Program.GetDbConn(),
        WorkId: 1,
        AppId: 1
    }

    public service: tspayService;
    public dao: tspayDao;
    public mchservice: mchService;
    public payservice: payService;
    public refundservice: refundService;
    public billservice: billService;
    public realtimeservice: realtimeService;

    constructor() {
        this.data.WorkId = TSLobsterAPI.Program.GetWorkId();
        this.data.AppId = TSLobsterAPI.Program.GetAppId();

        this.service = new tspayService(this.data.WorkId);
        this.dao = new tspayDao(this.data.WorkId);
        this.mchservice = new mchService(this.data.WorkId, this.data.AppId);
        this.payservice = new payService(this.data.WorkId, this.data.AppId);
        this.refundservice = new refundService(this.data.WorkId, this.data.AppId);
        this.billservice = new billService(this.data.WorkId, this.data.AppId);
        this.realtimeservice = new realtimeService(this.data.WorkId, this.data.AppId);
    }


    /**
     * 获取支付方式
     */
    getdic_paytype() {
        let data = TSLobsterAPI.AppFunction.GetAppBaseDict(this.data.AppId, '8331');
        return { data: data };
    }
    /**
     * 获取订单类型
     */
    getdic_ordertype() {
        let data = TSLobsterAPI.AppFunction.GetAppBaseDict(this.data.AppId, '8329');
        return { data: data };
    }

    /**
     * 支付渠道设置
     */
    getmchlist() {

        var page = TSLobsterAPI.Program.RequestQuery("page", "1");
        var perPage = TSLobsterAPI.Program.RequestQuery("limit", "10");
        var searchkey = TSLobsterAPI.Program.RequestQuery("searchkey") || "";

        return this.mchservice.getmchlist(page, perPage, searchkey);
    }
    /**
     * 保存支付渠道
     */
    savemch() {
        let mchobj = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.mchservice.savemch(mchobj);
        return { result: true };
    }

    /**
     * 设置商户号密码
     */
    setpwd() {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.mchservice.setpwd(model);
        return { result: true };
    }
    /**
     * 停用启用商户号
     */
    setdelflag() {
        let id = TSLobsterAPI.Program.RequestQuery('id');
        let status = TSLobsterAPI.Program.RequestQuery('status');
        this.mchservice.setdelflag(id, status);
        return { result: true };
    }
    /**
     * 获取支付方式配置
     */
    getpaymentlist() {
        var subMchId = TSLobsterAPI.Program.RequestQuery('subMchId');
        return this.mchservice.getpaymentlist(subMchId);
    }
    /**
     * 保存支付方式配置
     */
    savepayment() {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.mchservice.savepayment(model);
        return { result: true };
    }

    /**
     * 获取支付交易记录
     */
    getpaylist() {
        var page = TSLobsterAPI.Program.RequestQuery("page", "1");
        var perPage = TSLobsterAPI.Program.RequestQuery("limit", "10");
        var orderNo = TSLobsterAPI.Program.RequestQuery("orderNo", '');
        var paystate = TSLobsterAPI.Program.RequestQuery("paystate", '');
        var orderType = TSLobsterAPI.Program.RequestQuery("orderType", '');
        var sdate = TSLobsterAPI.Program.RequestQuery("sdate", '');
        var edate = TSLobsterAPI.Program.RequestQuery("edate", '');

        return this.payservice.getpaylist(page, perPage, orderNo, paystate, orderType, sdate, edate);
    }

    /**
     * 后台退款
     */
    refundforself() {
        let model = JSON.parse(TSLobsterAPI.Program.RequestBody());

        return this.payservice.refundforself(model);
    }

    getrefundlistdetail() {
        var orderNo = TSLobsterAPI.Program.RequestQuery("orderNo", '');

        return this.payservice.getrefundlistdetail(orderNo);
    }

    /**
     * 获取退款记录
     */
    getrefundlist() {
        var page = TSLobsterAPI.Program.RequestQuery("page", 0);
        var limit = TSLobsterAPI.Program.RequestQuery("limit", 0);
        var orderNo = TSLobsterAPI.Program.RequestQuery("orderNo", '');
        var refundStatus = TSLobsterAPI.Program.RequestQuery("refundStatus", '');
        var sdate = TSLobsterAPI.Program.RequestQuery("sdate", '');
        var edate = TSLobsterAPI.Program.RequestQuery("edate", '');

        return this.refundservice.getrefundlist(page, limit, orderNo, refundStatus, sdate, edate);
    }



    gettransactionlist() {
        var page = TSLobsterAPI.Program.RequestQuery("page", 0);
        var limit = TSLobsterAPI.Program.RequestQuery("limit", 0);
        var type = TSLobsterAPI.Program.RequestQuery("type", '');
        var sdate = TSLobsterAPI.Program.RequestQuery("sdate", '');
        var edate = TSLobsterAPI.Program.RequestQuery("edate", '');

        return this.billservice.gettransactionlist(page, limit, type, sdate, edate);
    }

    getbillreport() {
        var sdate = TSLobsterAPI.Program.RequestQuery("sdate", '');
        var edate = TSLobsterAPI.Program.RequestQuery("edate", '');
        var type = TSLobsterAPI.Program.RequestQuery("type", '');

        return this.billservice.getreport(sdate, edate, type);
    }

    getchartdata() {
        var type = TSLobsterAPI.Program.RequestQuery("type", 0);
        return this.realtimeservice.getchartdata(type);
    }
}